Document Type Definitions

You have probably guessed how we are going to control the structure of our XML content.  We are going to use a document type definition (DTD).  Similar to a SQL script, a DTD is used to define the structure of the content that the XML document will contain.  If the content does not conform to the structure, the XML processor will generate warnings and/or errors.

Tip:	While you may be very familiar with content modeling in the world of relational databases, you may find it a little more challenging in XML.  This is because XML is hierarchical in nature, not relational.  With a little practice however, you will be able to switch between the models with ease.

DTD’s may remind you of SQL scripts like the one we created previously, but  DTD’s go well beyond simple structure definition as you will soon learn.  

For now, let’s define the content model for our employees document.  We are not yet ready to dive into external DTD’s, so let’s pick up where we last left off with the declaration of a DTD.

<!DOCTYPE employees [
	<!-- This is where the content model 
		  will be defined. 
	-->
]>

Notice that we named our DTD “employees”.  It is the same name as the root element.  Remember: you must always name your DTD’s the same name as your root element!  Since XML is case-sensitive, this includes matching the case as well as the spelling.  

Tip:	XML requires that we be specific in our content model.  XML processors are less than forgiving when your elements do not match your logical structure.  Content models can only be interpreted one way by an XML processor, so make sure that your models represent your logical structure correctly.

To dive into DTD’s and XML content modeling, we are going to define the employee content model using XML.